package hessionBusiness;

import MyObject.User;
import models.MyConfig;
import models.ReturnJson;
import models.TestServerBusinessImpl;

import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.io.ObjectInputStream;

/**
 * Created by yangxianming on 2024/2/8.
 * http传输序列化对象，关键要将对象独立打包，并将装有对象的jar包在发送端和接收端都导入一份
 * 如果包不同，反序列化的时候就会出现找不到包的情况
 */
public class ReceiveUser implements TestServerBusinessImpl {
    @Override
    public String doIt(HttpServletRequest request, MyConfig myConfig) {
        ReturnJson returnJson = new ReturnJson();
        System.out.println("receive user start");
        try {
            InputStream inputStream = request.getInputStream();

//            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
//            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
//            String requestInfo = "";
//            String line;
//            while ((line = bufferedReader.readLine()) != null)
//                requestInfo = requestInfo + line;
//            System.out.println(requestInfo);


            ObjectInputStream oin = new ObjectInputStream(inputStream);
            User user = (User)oin.readObject();
            System.out.println(user.getName());


        }catch (Exception e){
            e.printStackTrace();
        }


        return "ok";
    }
}
